%{
%%-------------------------------------------------------------------------
Plots output from the 2-state Huggett economy

    Note: must have output from 3 presentBias cases for code to run fully
%%-------------------------------------------------------------------------
%}

%% Beta<1 vs. Beta=1
%%-------------------------------------------------------------------------
%Unpack Structs / Setup
    load('output/beta0pt75_output.mat');
        beta = prefStruct.beta;
        Cbd_ = C_;
        Sbd_ = S_;
        gbd = g;
        MPCbd_ = MPC_;
        betalow = prefStruct.beta;
        rholow = prefStruct.rho;
    load('output/beta1_output.mat');

    beta = betalow;

    X_ = Xstruct.X_;
    xjump = Xstruct.xjump;
    borrowingLimit = Xstruct.borrowingLimit;

    colorB1 = [0 0 0];
    colorPB = [1 0 0];

%%-------------------------------------------------------------------------


%%-------------------------------------------------------------------------
%Plots 

%Consumption
fig = figure;
plot(X_(2:end), Cbd_(2:end, 1), 'Color', colorPB, 'LineWidth', 2.5); hold on
plot(X_, Cbd_(:, 2), 'Color', colorPB, 'LineWidth', 2.5, 'Linestyle', '--');
plot(X_, C_(:, 1), 'Color', colorB1, 'LineWidth', 2);
plot(X_, C_(:, 2), 'Color', colorB1, 'LineWidth', 2, 'Linestyle', '--');
plot(X_(1), Cbd_(2, 1), 'o', 'Color', colorPB, 'MarkerFaceColor', 'white', 'MarkerSize', 12);
plot(X_(1), Cbd_(1, 1), 'o','Color', colorPB, 'MarkerFaceColor', colorPB, 'MarkerSize', 12);
    xlim([borrowingLimit, 10]); ylim([.6, 1.5]);
    set(gca, 'FontSize', 16);
    legend(['$y_1 \ (\beta = $',num2str(beta),')'], ['$y_2 \ (\beta = $',num2str(beta),')'], '$y_1 \ (\beta = 1)$', '$y_2 \ (\beta = 1)$', 'Location', 'Northwest', 'Interpreter', 'Latex', 'FontSize', 20)
    grid on
    xlabel('Wealth ($b$)', 'FontSize', 22 , 'Interpreter', 'Latex')
    ylabel('Consumption', 'FontSize', 22, 'Interpreter', 'Latex')
    saveas(fig, ['figs/Figure2_consumption.png']);
hold off



%Saving
fig = figure;
plot(X_(2:end), Sbd_(2:end, 1), 'Color', colorPB, 'LineWidth', 2.5); hold on
plot(X_, Sbd_(:, 2), 'Color', colorPB, 'LineWidth', 2.5, 'Linestyle', '--');
plot(X_, S_(:, 1), 'Color', colorB1, 'LineWidth', 2);
plot(X_, S_(:, 2), 'Color', colorB1, 'LineWidth', 2, 'Linestyle', '--');
plot(X_(1), Sbd_(2, 1), 'o', 'Color', colorPB, 'MarkerFaceColor', 'white', 'MarkerSize', 12);
plot(X_(1), Sbd_(1, 1), 'o', 'Color', colorPB, 'MarkerFaceColor', colorPB, 'MarkerSize', 12);
plot(X_, zeros(length(X_),1), 'black','LineWidth', 3);
    xlim([borrowingLimit, 10]); ylim([-0.4, 0.4]);
    set(gca, 'FontSize', 16);
    grid on
    xlabel('Wealth ($b$)', 'FontSize', 22 , 'Interpreter', 'Latex')
    ylabel('Saving', 'FontSize', 22, 'Interpreter', 'Latex')
    saveas(fig, ['figs/Figure2_saving.png']);
hold off



%Distributions (PDF)
fig = plot(X_, gbd(:, 1), 'Color', colorPB, 'LineWidth', 2.5); hold on
plot(X_, gbd(:, 2), 'Color', colorPB, 'LineWidth', 2.5, 'Linestyle', '--');
plot(X_, g(:, 1), 'Color', colorB1, 'LineWidth', 2);
plot(X_, g(:, 2), 'Color', colorB1, 'LineWidth', 2, 'Linestyle', '--');
    xlim([borrowingLimit, 10])
    ylim([0,0.15])
    set(gca, 'FontSize', 16, 'Yticklabel', []);
    legend(['$y_1 \ (\beta = $',num2str(beta),')'], ['$y_2 \ (\beta = $',num2str(beta),')'], '$y_1 \ (\beta = 1)$', '$y_2 \ (\beta = 1)$', 'Location', 'Northeast', 'Interpreter', 'Latex', 'FontSize', 16)
    grid on
    xlabel('Wealth ($b$)', 'FontSize', 22 , 'Interpreter', 'Latex')
    ylabel('Density', 'FontSize', 22, 'Interpreter', 'Latex')
    text(borrowingLimit + 0.03,.965*0.15,['\leftarrow ', num2str(round(100*sum(gbd(1,1:2))*xjump,1)), '% (\beta = ', num2str(beta), ')'], 'FontSize', 18, 'Color', colorPB);
    text(borrowingLimit + 0.03,.9*0.15,['\leftarrow ', num2str(round(100*sum(g(1,1:2))*xjump,1)), '% (\beta = 1)'], 'FontSize', 18);
    saveas(fig, ['figs/Figure3.png']);
hold off



%MPC
fig = plot(X_(1:end-1), MPCbd_(:, 1), 'Color', colorPB, 'LineWidth', 2.5); hold on
plot(X_(1:end-1), MPCbd_(:, 2), 'Color', colorPB, 'LineWidth', 2.5, 'Linestyle', '--');
plot(X_(1:end-1), MPC_(:, 1), 'Color', colorB1, 'LineWidth', 2);
plot(X_(1:end-1), MPC_(:, 2), 'Color', colorB1, 'LineWidth', 2, 'Linestyle', '--');
    xlim([borrowingLimit, 1]); ylim([0,1]);
    set(gca, 'FontSize', 16);
    legend(['$y_1 \ (\beta = $',num2str(beta),')'], ['$y_2 \ (\beta = $',num2str(beta),')'], '$y_1 \ (\beta = 1)$', '$y_2 \ (\beta = 1)$', 'Location', 'Northeast', 'Interpreter', 'Latex', 'FontSize', 20)
    grid on
    xlabel('Wealth ($b$)', 'FontSize', 22 , 'Interpreter', 'Latex')
    ylabel('Quarterly MPC', 'FontSize', 22, 'Interpreter', 'Latex')
    saveas(fig, ['figs/Figure4.png']);
hold off






%% Sophisticate vs. Naif 
%%-------------------------------------------------------------------------
%Unpack Structs / Setup
    load('output/beta0pt75_output.mat');
        beta = prefStruct.beta;
        Cbd_ = C_;
        Sbd_ = S_;
        gbd = g;
        MPCbd_ = MPC_;
        betalow = prefStruct.beta;
    load('output/beta0pt75_betaE1_output.mat');

    beta = betalow;

    X_ = Xstruct.X_;
    xjump = Xstruct.xjump;
    borrowingLimit = Xstruct.borrowingLimit;

%%-------------------------------------------------------------------------


%%-------------------------------------------------------------------------
%Plots

%Consumption
fig = figure;
plot(X_(2:end), Cbd_(2:end, 1), 'Color', colorPB, 'LineWidth', 2.5); hold on
plot(X_, Cbd_(:, 2), 'Color', colorPB, 'LineWidth', 2.5, 'Linestyle', '--');
plot(X_(2:end), C_(2:end, 1), 'Color', 'blue', 'LineWidth', 2);
plot(X_, C_(:, 2), 'Color', 'blue', 'LineWidth', 2, 'Linestyle', '--');
plot(X_(1), Cbd_(2, 1), 'o', 'Color', colorPB, 'MarkerFaceColor', 'white', 'MarkerSize', 10);
plot(X_(1), Cbd_(1, 1), 'o', 'Color', colorPB, 'MarkerFaceColor', colorPB, 'MarkerSize', 12);
plot(X_(1), C_(2, 1), 'blueo', 'MarkerFaceColor', 'white', 'MarkerSize', 10);
plot(X_(1), C_(1, 1), 'blueo', 'MarkerFaceColor', 'blue', 'MarkerSize', 6);
    xlim([borrowingLimit, 10]); ylim([.6, 1.5]);
    set(gca, 'FontSize', 16);
    legend(['$y_1 \ (\beta^E = \beta$)'], ['$y_2 \ (\beta^E = \beta$)'], '$y_1 \ (\beta^E = 1)$', '$y_2 \ (\beta^E = 1)$', 'Location', 'Northwest', 'Interpreter', 'Latex', 'FontSize', 20)
    grid on
    xlabel('Wealth ($b$)', 'FontSize', 22 , 'Interpreter', 'Latex')
    ylabel('Consumption', 'FontSize', 22, 'Interpreter', 'Latex')
    saveas(fig, ['figs/Figure5.png']);
hold off



%MPC
fig = plot(X_(1:end-1), MPCbd_(:, 1), 'Color', colorPB, 'LineWidth', 2.5); hold on
plot(X_(1:end-1), MPCbd_(:, 2), 'Color', colorPB, 'LineWidth', 2.5, 'Linestyle', '--');
plot(X_(1:end-1), MPC_(:, 1), 'blue', 'LineWidth', 2);
plot(X_(1:end-1), MPC_(:, 2), 'blue', 'LineWidth', 2, 'Linestyle', '--');
    xlim([borrowingLimit, 1]); ylim([0,1]);
    set(gca, 'FontSize', 16);
    legend(['$y_1 \ (\beta^E = \beta$)'], ['$y_2 \ (\beta^E = \beta$)'], '$y_1 \ (\beta^E = 1)$', '$y_2 \ (\beta^E = 1)$', 'Location', 'Northeast', 'Interpreter', 'Latex', 'FontSize', 16)
    grid on
    xlabel('Wealth ($b$)', 'FontSize', 22 , 'Interpreter', 'Latex')
    ylabel('Quarterly MPC', 'FontSize', 22, 'Interpreter', 'Latex')
    saveas(fig, ['figs/Figure6.png']);
hold off



